package Servlet;

import com.cyy.dao.loginRecordDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/clearLoginRecord")
public class clearLoginRecordServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userName=request.getSession().getAttribute("name").toString();
        int identity=Integer.parseInt(request.getSession().getAttribute("identity").toString());
        loginRecordDao loginRecordDao = new loginRecordDao();
        try {
//            清空该用户的所有登录记录
            loginRecordDao.deleteAll(userName,identity);
        } catch (SQLException | ClassNotFoundException throwables) {
            throwables.printStackTrace();
        }
        request.getRequestDispatcher("/showMyInfo").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
